/*
Copyright (C) 2008 raohmaru <http://www.raohmaru.com>

This file is part of Raohmaru AS3 Framework.

Raohmaru AS3 Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Raohmaru AS3 Framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Raohmaru AS3 Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

package jp.raohmaru.form 
{

/**
 * Utilidad para el tratamiento de campos de texto. 
 * @author raohmaru
 * @version 1.1
 */
public class TextUtil 
{
	/**
	 * Obtiene una cadena con los caracteres restringidos según el tipo especificado.
	 * @param type Tipo de restricción
	 * @return Cadena con caracteres a restringir
	 * @see flash.text.TextField#restrict
	 * @example
	<listing version="3.0">
	import jp.raohmaru.form.FormType;
	import jp.raohmaru.form.TextUtil;<br>
	email_input.restrict = TextUtil.getRestrictChars(FormType.EMAIL);</listing>
	 */
	public static function getRestrictChars(type : String) : String
	{
		var rchars : String;
		
		switch(type)
		{
			case FormElementType.EMAIL:
				rchars = "0-9a-zA-Z\\-+._@";
				break;
				
			case FormElementType.TEXT:
			case FormElementType.PASSWORD:			case FormElementType.DATE:
				//rchars = "0-9a-zA-Z ÀÁÄÇÈÉËÌÍÏÑÒÓÖÙÚÜàáäçèéëìíïñòóöùúü¡!#$%()*+,\\-./:;=¿?@[]_ {|}€ºª·";
				rchars = "0-9a-zA-Z ÀÁÄÇÈÉËÌÍÏÑÒÓÖÙÚÜàáäçèéëìíïñòóöùúü!\"#$%&'()*+,\\-./:;<=>?@[]_{|}¡€ª·º¿";	
				break;
				
			case FormElementType.NUMBER:
				rchars = "0-9.";
				break;
				
			case FormElementType.POSTAL_CODE:
			case FormElementType.MOBILE:
			case FormElementType.PHONE:			case FormElementType.PHONE_MOBILE:
				rchars = "0-9";
				break;
				
			case FormElementType.DNI:
				rchars = "0-9a-zA-Z";
				break;
				
			// Caracteres personalizados
			default:
				rchars = type;
		}
		
		return rchars;
	}
}
}